package com.caigou.modules.forum.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Window
import android.widget.Button
import android.widget.RadioButton
import android.widget.RadioGroup
import com.alibaba.android.arouter.launcher.ARouter
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.modules.forum.R

/**
 * @author #Suyghur.
 * Created on 2021/12/25
 */
class ContestTypeDialog(context: Context, private val forumType: Int) : Dialog(context) {

    private lateinit var rgSelector: RadioGroup
    private lateinit var btnTeXiao: RadioButton
    private lateinit var btnTeMa: RadioButton
    private lateinit var btnPingMa: RadioButton
    private lateinit var btnConfirm: Button

    private var dareType = 1

    init {
        setCanceledOnTouchOutside(true)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        initView()
    }

    private fun initView() {
        setContentView(R.layout.dialog_contest_type)

        rgSelector = findViewById(R.id.contest_type_dialog_rg_selector)
        btnTeXiao = findViewById(R.id.contest_type_dialog_btn_te_xiao)
        btnTeMa = findViewById(R.id.contest_type_dialog_btn_te_ma)
        btnPingMa = findViewById(R.id.contest_type_dialog_btn_ping_ma)
        btnConfirm = findViewById(R.id.contest_type_dialog_btn_confirm)

        rgSelector.setOnCheckedChangeListener { _, checkedId ->
            dareType = when (checkedId) {
                R.id.contest_type_dialog_btn_te_xiao -> 1
                R.id.contest_type_dialog_btn_te_ma -> 2
                R.id.contest_type_dialog_btn_ping_ma -> 3
                else -> 1
            }
        }

        btnConfirm.setOnClickListener {
            ARouter.getInstance().build(RouterPath.Forum.PAGE_PUBLISH_CONTEST)
                .withInt(AppConstants.DARE_TYPE, dareType)
                .withInt(AppConstants.FORUM_TYPE, forumType)
                .navigation()
            dismiss()
        }
    }

}